<template>
  <div>
    <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="以下地址超出配送范围"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="onselect"
    />
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  name: "addressList",
    data() {
      return {
        chosenAddressId: '1',
        list: [
          {
            id: '1',
            name: '张三',
            tel: '13000000000',
            address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
            isDefault: true,
            areaCode: 110109
          },
          {
            id: '2',
            name: '李四',
            tel: '1310000000',
            address: '浙江省杭州市拱墅区莫干山路 50 号',
            areaCode: 110110
          },
        ],
        disabledList: [
          {
            id: '3',
            name: '王五',
            tel: '1320000000',
            address: '浙江省杭州市滨江区江南大道 15 号',
          },
        ],
        url: null,
        score: null,
      };
    },
  created() {
    this.url = this.$route.query.url
    this.score = this.$route.query.score
    console.log("参数",this.url,this.score)
  },
  methods: {
      onAdd() {
        Toast('新增地址');
        this.$router.push("/addressNew")
      },
      onEdit(item, index) {
        /*console.log(item)*/
        let data = JSON.stringify(item)
        console.log("数据",data)
        this.$router.push({path:'/addressEdit',query:{item: data}})
      },
      onselect(item) {
        console.log(item)
        let instance = Toast("下单成功");
        setTimeout(()=>{instance.close();
        this.$router.push({path:'/detail',query:{
            url: this.url,
            score: this.score,
            username: item.name,
            tel: item.tel,
            address: item.address,
            flag: this.$route.query.flag
          }})},1000)
      },
    },
}
</script>

<style scoped>

</style>